package rensoft.android.presenter;

import android.view.View;
import rensoft.android.HasActivityPresenter;

public abstract class ApplicationViewBase extends HasActivityPresenter implements ApplicationView {

  private final int layoutId;

  public ApplicationViewBase(IApplicationPresenter applicationPresenter, int layoutId) {
    super(applicationPresenter);
    setActive(false);
    this.layoutId = layoutId;
    applicationPresenter.addApplicationView(getId(), this);
  }

  public View createView() {
    return inflateLayout(layoutId);
  }

  public String getId() {
    return layoutId + "";
  }

  public final void onApplicationViewGoesToBackground() {
    setActive(false);
    onPause();
    onStop();
  }

  public final void onApplicationViewGoesToForeground(boolean isCreate) {
    setActive(true);
    if (!isCreate) {
      onCreate(null);
      onStart();
      onResume();
    }
  }
}
